package com.x.erp.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.RotationDao;
import com.x.erp.model.Rotation;
import com.x.erp.rpc.RotationRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;

@Component
@Service(interfaceName = "com.x.erp.rpc.RotationRpcService", timeout = 60000)
public class RotationService extends BaseService implements RotationRpcService {

	@Autowired
	private RotationDao rotationDao;

	/**
	 * 轮播图列表
	 *
	 * @param rotation
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Rotation> selectRotationList(Rotation rotation) {
		try {
			return rotationDao.selectRotationList(rotation);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 轮播图数量
	 *
	 * @param rotation
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer selectRotationListNum(Rotation rotation) {
		try {
			return rotationDao.selectRotationListNum(rotation);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 新增轮播图
	 *
	 * @param rotation
	 * @return
	 * @throws Exception
	 */
	@Override
	public Rotation insertRotation(Rotation rotation) {
		try {
			rotation.setRotationCreateTime(this.getDate(0));
			rotation.setRotationUpdateTime(this.getDate(0));
			return this.insert(rotation);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 编辑轮播图
	 *
	 * @param rotation
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer updateRotation(Rotation rotation) {
		try {
			rotation.setRotationUpdateTime(this.getDate(0));
			int update = this.update(rotation);
			return update;
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

}